  //NEW
   
    public void Bewaren()
    {
        //Bewaar de bestelling:
        Insert(this);

        //En de kaarten van de bestelling:
        foreach (Kaart oKaart in this.Kaarten)
        {
            oKaart.BestellingID = this.ID;
            Kaart.Insert(oKaart);
        }
    }

    //NEW
    private void Insert(Bestelling nieuweBestelling)
    {
        string sql = "INSERT INTO Bestelling(KlantID, Status)" +
        " VALUES (@pmKlantID, @pmStatus);" +
        "SELECT @@IDENTITY;";

        using (SqlConnection cn = DataClass.GetConnection())
        {
            SqlCommand com = new SqlCommand(sql, cn);
            com.Parameters.AddWithValue("@pmKlantID", nieuweBestelling.KlantID);
            com.Parameters.AddWithValue("@pmStatus", nieuweBestelling.Status);


            cn.Open();
            int iNewID = Convert.ToInt32(com.ExecuteScalar());
            nieuweBestelling.ID = iNewID;
        }
    }

    //NEW
    //Ophalen
    public static Bestelling Select(int BestellingID)
    {
        string sql = "KlantID, Datum, Status WHERE ID = @pmID";
        Bestelling oBestelling = null;

        using (SqlConnection cn = DataClass.GetConnection())
        {
            SqlCommand com = new SqlCommand(sql, cn);
            com.Parameters.AddWithValue("@pmID", BestellingID);
            cn.Open();
            SqlDataReader reader = com.ExecuteReader();

            if (reader.Read())
            {
                oBestelling = new Bestelling();

                oBestelling.ID = oBestelling.ID;
                oBestelling.KlantID = oBestelling.KlantID;
                oBestelling.Status = reader.GetInt32(8);
                oBestelling.Datum = reader.GetDateTime(9);
            }
            return oBestelling;
        }
    }

    //NEW
    public static DataTable SelectAll(int KlantID)
    {
        string sql = "SELECT b.ID AS BestellingID, b.KlantID, b.Datum, b.Status, Count(k.ID) AS AantalKaarten FROM Bestelling b " +
            "INNER JOIN Kaarten k ON b.ID = k.BestellingID " +
            "GROUP BY b.ID, b.KlantID, b.Datum, b.Status " +
            "HAVING b.KlantID = @pmKlantID ORDER BY DATUM ASC";

        DataTable dt = new DataTable();

        using (SqlConnection cn = DataClass.GetConnection())
        {
            SqlDataAdapter da = new SqlDataAdapter(sql, cn);
            da.SelectCommand.Parameters.AddWithValue("@pmKlantID", KlantID);
            da.Fill(dt);

            return dt;
        }
    }